/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} p
 * @param {TreeNode} q
 * @return {boolean}
 */
 var isSameTree = function(p, q) {
    return (inorder(p,q));
};

const inorder = (node1, node2) => {
    if(node1 != null && node2 != null){
        if(!inorder(node1.left, node2.left)){
            return false;
        }
        if(node1.val != node2.val){
            return false;
        }
        if(!inorder(node1.right, node2.right)){
            return false;
        }
    }else if(node1 == null && node2 != null){
        return false;
    }else if(node1 != null && node2 == null){
        return false;
    }
    return true;
}